package api.my_api;

import java.util.Arrays;

public class Test5 {
    public static void main(String[] args) {
        int[] arr = {5,4,3,2,1};
        bubbleSearch(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void bubbleSearch(int[] arr){
        if (arr == null || arr.length <= 1){
            return;
        }
        for (int i = 0; i < arr.length - 1; i++) {
            boolean flag = true;
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]){
                    arr[j] = arr[j] ^ arr[j + 1];
                    arr[j + 1] = arr[j] ^ arr[j + 1];
                    arr[j] = arr[j + 1] ^ arr[j];
                    flag = false;
                }
            }
            if (flag) {break;}
        }
    }
}
